<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:ddl="livcos.org/ns/db/ddl"
  xmlns:pm="livcos.org/ns/pm"
  xmlns:sd="livcos.org/ns/design/system"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:v="livcos.org/ns/view"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="c doc ddl pm sd f v xs">
  
  <xsl:import href="base.xsl"/>
  
	<xsl:template match="ddl:procedure" mode="ddl_content">
		<table class="table_overview">
			<thead>
				<tr>
					<th>Parameter</th>
					<th>Type</th>
					<th>Dimension</th>
				</tr>
			</thead>
			<tbody>
				<xsl:apply-templates select="ddl:param" mode="ddl_proc_overview">
					<xsl:sort select="lower-case(@name)"/>
				</xsl:apply-templates>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="3" class="table_legend">
						<span class="mandatory">&#160;&#160;</span>
						<xsl:text> Mandatory&#160;&#160; </xsl:text>
						<span class="nullable">&#160;&#160;</span>
						<xsl:text> Optional (allow NULL)</xsl:text>
					</td>
				</tr>
			</tfoot>
		</table>
		<xsl:call-template name="ddl_doc"/>
		<v:chapter>
			<v:title>Parameter</v:title>
			<xsl:apply-templates select="ddl:param" mode="ddl_proc">
				<xsl:sort select="lower-case(@name)"/>
			</xsl:apply-templates>
		</v:chapter>
		<v:chapter>
			<v:title>Definition</v:title>
			<xsl:apply-templates select="ddl:def"/>
		</v:chapter>
  </xsl:template>
  
	<xsl:template match="ddl:param" mode="ddl_proc_overview">
    <tr>
      <xsl:attribute name="class">
        <xsl:choose>
          <xsl:when test="@nullable">nullable</xsl:when>
          <xsl:otherwise>mandatory</xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <td>
        <a href="#{@id}"><xsl:value-of select="@name"/></a>
      </td>
      <td align="center">
        <xsl:value-of select="@dbtype" />
      </td>
      <td align="center">
      	<xsl:apply-templates select="@size"/>
      	<xsl:if test="not(@size)">&#160;</xsl:if>
      </td>
    </tr>
  </xsl:template>
  
  <xsl:template match="ddl:param" mode="ddl_proc">
  	<v:chapter id="{@id}">
  		<v:title>
  			<xsl:call-template name="ddl-search">
  				<xsl:with-param name="label" select="string(@name)"/>
  				<xsl:with-param name="query" select="concat(@name, ' AND ', ../@name)"/>
  			</xsl:call-template>
  		</v:title>
    	<xsl:apply-templates select="*"/>
    	<p class="block">
    		<xsl:text>Der </xsl:text>
    		<xsl:if test="@nullable">optionale</xsl:if> Parameter '<xsl:value-of select="@name"/>
    		<xsl:text>' akzeptiert Werte vom Typ </xsl:text>
    		<xsl:apply-templates select="." mode="ddl_type"/>
    		<xsl:text>.</xsl:text>
      </p>
    </v:chapter>
  </xsl:template>

</xsl:stylesheet>
